package com.example.yiwei.crm.view.Class.listviewClass;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.entity.GiftEntity;

import java.util.List;

/**
 * Created by DHN on 2017/4/28.
 */

public class GiftAdapter extends BaseAdapter{
    private List<GiftEntity> list;
    private GiftEntity giftEntity;
    private LayoutInflater inflater ;
    private Context context;
    public GiftAdapter(Context context, List<GiftEntity> list){
        this.context = context;
        this.list = list;
        inflater =LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        giftEntity = list.get(position);
        if (convertView==null){
            convertView = inflater.inflate(R.layout.layout_item_gift,null);
            holder = new ViewHolder();
            holder.bfname = (TextView) convertView.findViewById(R.id.item_gift_bfname);
            holder.giftname = (TextView) convertView.findViewById(R.id.item_gift_name);
            holder.gifemoney = (TextView) convertView.findViewById(R.id.item_gift_money);
//            holder.cname = (TextView) convertView.findViewById(R.id.item_gift_cname);
//            holder.cdata = (TextView) convertView.findViewById(R.id.item_gift_cdata);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.bfname.setText(giftEntity.getBfname());
        holder.giftname.setText("礼品名："+giftEntity.getGiftname());
        holder.gifemoney.setText(giftEntity.getGiftmonery()+"元");
//        holder.cname.setText(giftEntity.getCname());
//        holder.cdata.setText(giftEntity.getCdata());
        return convertView;
    }

    class ViewHolder{
        TextView bfname;
        TextView giftname;
        TextView gifemoney;
        TextView cname;
        TextView cdata;
    }
}
